<?php

class Config {
	
	private static $db_data_source_template_mysql 	= "mysql:dbname=%s;host=%s;port=%s;charset=%s";
	
	private static $root = null;
	
	private static $documentRoot = null;
	
	private static $config = array( 
				"database" => array(
					"host" => "localhost",
					"port" => 3306,
					"name" => "leaguemanager",
					"username" => "root",
					"password" => "root",
					"dialect" => "mysql",
					"charset" => "utf-8"
				),			
				"configuration" => array(
					"locale" => "pt_br",
					"date-format" => "d/m/Y H:i:s",
					"view-package" => "classes/view",
					"model-package" => "classes/model",
					"action-package" => "classes/action",
					"service-package" => "classes/service",
					"dao-package" => "classes/dao",
					"template-package" => "classes/template",
					"logger-level" => "debug"
				),
				"reverse" => array(
					"autoexec" => false,
					"prefix-table" => "t_",
				)
			);
	
	
	public static function getConfig($name = null) {
		if( $name == null ) 
			return self::$config;
		else 
			return isset(self::$config[$name]) ? self::$config[$name] : null; 
	}
	
	public static function getDateSource() {
		$database = self::getConfig("database");
		$dialect = $database["dialect"];
		
		if( $dialect == "mysql" )
			return sprintf(self::$db_data_source_template_mysql, $database["name"], $database["host"], $database["port"], $database["charset"]);
		else 
			die("Dialect not found");
	}

	public static function getDocumentRoot() {
		if( self::$documentRoot == null ) self::$documentRoot = $_SERVER['DOCUMENT_ROOT'];
		return self::$documentRoot;
	}
	
	public static function setRoot($root) {
		if( self::$root == null ) self::$root = $root;
	}
	
	public static function getRoot() {
		return self::$root;
	}
	
	public static function getApplicationContext() {
		$str = self::getRoot();
		$rpc = self::getDocumentRoot();
		return StringUtils::replace($rpc, "", $str) . "/";
	}
	
	public static $cookie_duration = 172800; #60*60*24*2
}

Config::setRoot(realpath("."));
?>